import java.io.IOException;
import java.util.logging.*;

/**
 * 
 * @author Michael Zipp
 *
 */

public class Doctor extends Nurse{
	
	private Schedule schedule;

	private static Logger doctorLog = Logger.getLogger(Doctor.class.getName());
	
	static{
		ConsoleHandler console = new ConsoleHandler();
		console.setLevel(Level.ALL);
		console.setFormatter(new ThunderDragonHtmlFormatter());
		doctorLog.addHandler(console);
		doctorLog.setLevel(Level.ALL);
		
		try {
			FileHandler fh = new FileHandler("DoctorLog.txt");
			fh.setFormatter(new ThunderDragonHtmlFormatter());
			doctorLog.addHandler(fh);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			doctorLog.severe("Failure: Security exception thrown" +
					" when trying to create a new handler in Doctor.java.");
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			doctorLog.severe("Failure: I/O exception thrown " +
					"when trying to create a new handler in Doctor.java.");
			e.printStackTrace();
		}
		
	}

	/**
	 * Creates a new doctor user for the system.
	 * @param name Name of the doctor
	 * @param username User name for login
	 * @param password Password for login
	 * @param address Address of the doctor
	 * @param phoneNum Phone number of the doctor
	 * @param email Email address of the doctor
	 * @param age Age of the doctor
	 */
	public Doctor(String name, String username, String password, 
			String address, String phoneNum, String email, String age){
		super(name, username, password, address, phoneNum, email, age);
		usertype = "doctor";
		doctorLog.entering(this.getClass().getName(), "Doctor Overloaded Constructor", 
				new Object[] {name, username, password, address,
				phoneNum, email, age});
		
		schedule = new Schedule();
		
		doctorLog.exiting(this.getClass().getName(), "Doctor Overloaded Constructor");
	}
	
	public Doctor(){
		//super();
		usertype = "doctor";
		doctorLog.entering(this.getClass().getName(), "Doctor Default Constructor");
		
		schedule = new Schedule();
		
		doctorLog.exiting(this.getClass().getName(), "Doctor Default Constructor");
	}
	
	public Doctor(User user){
		name = user.name;
		username = user.username;
		password = user.password;
		address = user.address;
		phoneNum = user.phoneNum;
		email = user.email;
		age = user.age;
		usertype = "doctor";
	}

	/**
	 * Brings up a patients record for viewing
	 * @param p The Patient that is attached
	 * @return The Medical Record of the patient
	 */
	
	//Matt's note: I think it's better if we have the parameter be a Patient rather than a patient's Name
	public MedicalRecord viewReport(Patient p){
		//return null;
		//Search for patient
		//If no patient found, display so.
		//If found, return that patients Medical Record
		
		doctorLog.finest("Viewed the patient's report.");
		return(p.viewHistory());
	}

	/**
	 * Adds doctors orders to a specified treatment record.
	 * @param t Treatment Record to add Doc Orders to
	 * @param d	Doctors Orders being added.
	 */
	public void addDocOrders(TreatmentRecord t, DoctorOrders d){
		t.setDocOrders(d);
		doctorLog.finest("Exiting addDocOrders() in class Doctor.");
	}
	
	/**
	 * Removes doctor orders from a specific treatment record.  
	 * This is to fulfill a part of
	 * CRUD.  For the most part, all it'll do is declare it 'null'
	 */
	
	public void removeDocOrders(TreatmentRecord t){
		t.setDocOrders(null);
		doctorLog.finest("Exiting removeDocOrders() in class Doctor.");
	}
	
	/**
	 * Adds an appointment to the doctors schedule.
	 * @param a Appointment to be added.
	 */
	public void addAppointment(Appointment a){
		schedule.addAppointment(a);
		doctorLog.finest("Exiting addAppointment() in class Doctor.");
	}
	
	/**
	 * Returns a string.
	 * @return the string.
	 */
	public String toString(){
		return "This is the doc!";
	}
}
